package com.teamwechat.config.xss;

import io.swagger.annotations.ApiModelProperty;

import javax.servlet.*;
import javax.servlet.annotation.WebFilter;
import javax.servlet.http.HttpServletRequest;
import javax.validation.constraints.NotBlank;
import java.io.IOException;

@WebFilter(urlPatterns = "/*")//过滤所有请求
public class XssFilter  implements Filter {
    @Override
    public void init(FilterConfig filterConfig) throws ServletException {
        Filter.super.init(filterConfig);
    }

    @Override
    public void doFilter(ServletRequest servletRequest, ServletResponse servletResponse, FilterChain filterChain) throws IOException, ServletException {
        HttpServletRequest request= (HttpServletRequest) servletRequest;
        XssHttpServletRequestWrapper wrapper=new XssHttpServletRequestWrapper(request);
        filterChain.doFilter(wrapper,servletResponse);
    }

    @Override
    public void destroy() {
        Filter.super.destroy();
    }

    @NotBlank
    //@Pattern(regexp = "^[\\u4e00-\\u9fa5]{2,15}$",message = "姓名应为2-15中文")
    @ApiModelProperty("姓名：2-15中文")
    private String name;

}
